home *** CD-ROM | disk | FTP | other *** search
Wrap
(*^ ::[paletteColors = 128; currentKernel; fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L1, e8, 24, "Times"; ; fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L1, e6, 18, "Times"; ; fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, L1, e6, 14, "Times"; ; fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, L1, a20, 18, "Times"; ; fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, L1, a15, 14, "Times"; ; fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, L1, a12, 12, "Times"; ; fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 10, "Times"; ; fontset = input, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L1, 12, "Courier"; ; fontset = output, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; ; fontset = message, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1, 12, "Courier"; ; fontset = print, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1, 12, "Courier"; ; fontset = info, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1, 12, "Courier"; ; fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, L1, 12, "Courier"; ; fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, L1, 10, "Times"; ; fontset = header, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = Left Header, nohscroll, cellOutline, 12; fontset = footer, inactive, nohscroll, noKeepOnOnePage, preserveAspect, center, M7, L1, 12; fontset = Left Footer, cellOutline, blackBox, 12; fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 10, "Times"; ; fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12, "Courier"; ; fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; next21StandardFontEncoding; ] :[font = title; inactive; Cclosed; preserveAspect; startGroup; ] Lab 6: Sequences :[font = section; inactive; Cclosed; preserveAspect; startGroup; ] Simple Sequences :[font = text; inactive; preserveAspect; ] We studied sequences in Section 10.1 of Stein's textbook. This lab uses all three of Mathematica's facilities (graphical, analytical, and numerical) to assist this study. Pages 200-206 in the Crooke/Ratcliffe Guidebook cover this same material. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ] Example :[font = text; inactive; Cclosed; preserveAspect; startGroup; ] Here's an example we did in class: :[font = input; preserveAspect; ] a[n_] := (1+1/n)^n :[font = text; inactive; preserveAspect; endGroup; ] We know that this sequence converges to the constant e. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ] The Table command produces a subsequence of the sequence: ;[s] 3:0,0;3,1;10,2;58,-1; 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = input; preserveAspect; ] points = Table[ a[n], {n,1,8} ] :[font = text; inactive; preserveAspect; ] and the N command gives us their numerical (decimal) values: ;[s] 3:0,0;7,1;10,2;61,-1; 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = input; preserveAspect; endGroup; ] N[points] :[font = text; inactive; Cclosed; preserveAspect; startGroup; ] The ListPlot command produces a graphical indication of the convergence: ;[s] 3:0,0;3,1;13,2;73,-1; 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = input; preserveAspect; ] ListPlot[ points, PlotStyle -> PointSize[0.02] ]; :[font = text; inactive; preserveAspect; endGroup; ] Evidently, the points are leveling off at about 2.7. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ] Here's the Table command again. But this time we use 2^k in place of n to get the subsequence {a[2], a[4], a[8], a[16], a[32], a[64], a[128], a[256]}. This gets us closer to the limit faster, but it takes Mathematica a little longer to generate. ;[s] 11:0,0;10,1;17,2;53,3;58,4;69,5;72,6;94,7;150,8;207,9;218,10;247,-1; 11:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = input; preserveAspect; ] points = Table[ {2^k,a[2^k]}, {k,1,8} ] // N :[font = input; preserveAspect; ] TableForm[points] :[font = input; preserveAspect; endGroup; ] ListPlot[ points, PlotStyle -> PointSize[0.02] ]; :[font = text; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ] Finally, we try the Limit command to see if we can get the exact limit: ;[s] 3:0,0;19,1;26,2;72,-1; 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = input; preserveAspect; ] Limit[ a[n], n -> Infinity ] :[font = text; inactive; preserveAspect; ] and its numerical value: :[font = input; preserveAspect; ] N[%] :[font = input; preserveAspect; ] N[%,16] :[font = text; inactive; preserveAspect; endGroup; endGroup; ] Notice that Mathematics denotes the constant e by E. This is consistent with its rule that all predefined symbols are capitalized. ;[s] 3:0,0;12,1;23,2;131,-1; 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ] Exercises :[font = text; inactive; preserveAspect; ] For the sequence defined in each of the following exercises from our textbook: (a) define the function a[n_]; (b) use the Table command to produce a list of the first 8 terms; (c) use the ListPlot command to plot the points produced in (b); (d) use the Table command with 2^k in place of n, and with the // N function, to produce a table of terms indexed by the first 8 powers of 2; (e) use the ListPlot command to plot the points produced in (d); (f) use the Limit command to obtain the limit of the sequence, in both symbolic and numerical form. In other words, execute all the commands given in the example above. ;[s] 18:0,0;108,1;114,2;132,3;139,4;203,5;213,6;273,7;280,8;292,9;297,10;308,11;310,12;324,13;337,14;427,15;437,16;497,17;721,-1; 18:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0; :[font = text; inactive; preserveAspect; ] 1. Exercise 1 on page 494. :[font = text; inactive; preserveAspect; ] 2. Exercise 2 on page 494. :[font = text; inactive; preserveAspect; ] 3. Exercise 4 on page 494. :[font = text; inactive; preserveAspect; ] 4. Exercise 15 on page 494. :[font = text; inactive; preserveAspect; endGroup; endGroup; ] 5. The sequence n^(1/n). :[font = section; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ] Recursive Sequences :[font = text; inactive; preserveAspect; ] A recursive sequence is a sequence where the terms are defined in terms of previous terms, instead of being defined by a "closed" formula (i.e. a direct function of n). :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ] Example :[font = text; inactive; Cclosed; preserveAspect; startGroup; ] The Fibonacci sequence (Exercise 34 on page 495) is defined recursively: :[font = input; preserveAspect; ] Clear[f]; f[1] = 1; f[2] = 1; f[n_] := f[n-1] + f[n-2] :[font = text; inactive; preserveAspect; ] The recursion formula on the third line can be used by Mathematica to compute f[n] for any n > 2. ;[s] 7:0,0;55,1;66,2;79,3;84,4;91,5;94,6;101,-1; 7:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = text; inactive; Cclosed; preserveAspect; startGroup; ] For example: :[font = input; preserveAspect; ] f[3] :[font = input; preserveAspect; ] f[4] :[font = input; preserveAspect; endGroup; ] f[14] :[font = text; inactive; preserveAspect; endGroup; ] Of course, to compute f[14], it had to compute its predecessors f[3] through f[13] first. ;[s] 7:0,0;21,1;27,2;63,3;69,4;76,5;83,6;89,-1; 7:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = text; inactive; Cclosed; preserveAspect; startGroup; ] The Fibonacci sequence diverges, because it increases without bound. But Mathematica is unable to discover that fact. The following command will produce some error messages, but then it will continue to run. To abort it, give the Abort Calculation command in the Action>Interrupt submenu (or press Command- .). ;[s] 9:0,0;74,1;85,2;233,3;250,4;266,5;282,6;301,7;311,8;314,-1; 9:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,11,9,Helvetica,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,11,9,Helvetica,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,11,9,Helvetica,1,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = input; preserveAspect; ] f[n] :[font = text; inactive; preserveAspect; ] When you abort a running execution, Mathematica remembers your definitions. To check that it did, execute the following command which asks Mathematica for its current definition of the symbol f: ;[s] 7:0,0;36,1;47,2;140,3;151,4;192,5;194,6;195,-1; 7:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = input; preserveAspect; endGroup; endGroup; ] ?f :[font = subsection; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ] Exercises :[font = text; inactive; preserveAspect; ] For the sequence defined in each of the following exercises: (a) define the recursive function a[n_]; (b) use the Table command to produce a list of the first 8 terms; (c) use the ListPlot command to plot the points produced in (b); (d) Make a numerical estimate (to 4 decimal places) of the limit of the sequence. Use the same commands that you used in the first section. Remember to Clear[a]. ;[s] 9:0,0;100,1;106,2;124,3;131,4;195,5;205,6;406,7;415,8;417,-1; 9:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = text; inactive; preserveAspect; ] 1. The sequence of Fibonacci ratios: a[n] = f [n+1] / f [n]. (See part (c) of exercise 34 on page 494. ;[s] 3:0,0;37,1;60,2;112,-1; 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = text; inactive; preserveAspect; ] 2. a[n_] := 1/(1+a[n-1]); a[1] = 1; ;[s] 5:0,0;4,1;25,2;26,3;35,4;37,-1; 5:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = text; inactive; preserveAspect; ] 3. a[n_] := Sqrt[1+a[n-1]]; a[1] = 1; ;[s] 5:0,0;4,1;27,2;28,3;37,4;39,-1; 5:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = text; inactive; preserveAspect; endGroup; endGroup; ] 4. Exercise 35 on page 495. (Use a[n_] := (1+a[n-1])/a[n-2], a[1] = 1, and a[2] = 3). ;[s] 7:0,0;34,1;61,2;62,3;71,4;81,5;90,6;93,-1; 7:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = section; inactive; Cclosed; preserveAspect; startGroup; ] Newton's Method :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ] Example :[font = text; inactive; Cclosed; preserveAspect; startGroup; ] Recall Newton's method (Section 6.10) for numerically solving equations of the form f(x) = 0 If x is close to the solution, then ( x - f (x) / f'(x) ) will be closer. ;[s] 7:0,0;138,1;147,2;151,3;154,4;184,5;207,6;222,-1; 7:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = text; inactive; preserveAspect; ] For example, to find a numerical approximation to the sixth root of 2, we set up the function f[x_] := x^6 - 2 , so that the number we want is the solution to the equation x^6 - 2 = 0 Then x - f(x)/f'(x) = x - (x^6-2)/(6x^5) = (5x^6+2)/(6x^5). So we set up a recursive sequence a[n], with a[1]=1 and each successive a[n] computed from its predecessor using the above expression for x - f(x)/f'(x). ;[s] 15:0,0;93,1;110,2;221,3;233,4;289,5;344,6;380,7;385,8;391,9;399,10;418,11;424,12;484,13;499,14;500,-1; 15:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,0,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = input; preserveAspect; ] Clear[f]; f[x_] := x^6 - 2 :[font = input; preserveAspect; ] x - f[x]/f'[x] :[font = input; preserveAspect; ] a[n_] := a[n-1] - f[a[n-1]]/f'[a[n-1]]; a[1] := 1; :[font = input; preserveAspect; endGroup; ] Table[ a[n], {n,1,5} ] // N :[font = text; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ] Newton's Method converges rapidly. We see that the fifth iterate is correct to six significant digits: :[font = input; preserveAspect; ] Solve[f[x]==0,x] // N :[font = input; preserveAspect; endGroup; ] N[2^(1/6)] :[font = text; inactive; Cclosed; preserveAspect; startGroup; ] Another way to check the answer is to substitute it back into the original equation: :[font = input; preserveAspect; ] f[a[5]] // N :[font = text; inactive; preserveAspect; endGroup; endGroup; ] The answer here should be very close to zero. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ] Exercises :[font = text; inactive; preserveAspect; ] Use Newton's Method to solve the following equations, and then compare your fifth iterate with the output from the Solve command. Then check your answer by evaluating f[a[5]] // N . ;[s] 5:0,0;114,1;121,2;167,3;183,4;186,-1; 5:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = text; inactive; preserveAspect; ] 1. tan x = 1 - x^2 (Let f[x_] := 1 - x^2 - Tan[x]). ;[s] 3:0,0;26,1;52,2;55,-1; 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = text; inactive; preserveAspect; endGroup; endGroup; endGroup; ] 2. sin x = ln x (Let f[x_] := Sin[x] - Log[x]). ;[s] 3:0,0;23,1;48,2;51,-1; 3:1,11,8,Times,0,12,0,0,0;1,10,8,Courier,1,12,0,0,0;1,11,8,Times,0,12,0,0,0; ^*)